﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcWiki.Model
{
    public abstract class Entity
    {
        public Guid Id { get; set; }

        public Entity()
        {
            this.Id = Guid.NewGuid();
        }

        #region Object

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (object.ReferenceEquals(obj, null))
            {
                return false;
            }

            if (this.GetType() != obj.GetType())
            {
                return false;
            }

            var entity = obj as Entity;

            return this.Id == entity.Id;
        }

        public static bool operator ==(Entity entity1, Entity entity2)
        {
            if (object.ReferenceEquals(entity1, null) && object.ReferenceEquals(entity2, null))
            {
                return true;
            }

            if (object.ReferenceEquals(entity1, null) || object.ReferenceEquals(entity2, null))
            {
                return false;
            }

            return entity1.Equals(entity2);
        }

        public static bool operator !=(Entity entity1, Entity entity2)
        {
            return !(entity1 == entity2);
        }

        #endregion
    }
}